package org.example;

public class ThreadJoin implements Runnable {
    Thread driver, worker, administrator;
    public void setThread(Thread ... t) {
        driver = t[0];
        worker = t[1];
        administrator = t[2];
    }
        public void run() {
            if (Thread.currentThread() == driver) {
                System.out.println(driver.getName() + "等待" + worker.getName() + "搬运货物");
                try {
                    worker.start();
                    worker.join();
                }//当前线程开始等待 worker 结束｝
                catch (InterruptedException e) {
                }
                System.out.println(driver.getName() + "启动车辆，拉着货物离开了");
            } else if (Thread.currentThread() == worker) {
                System.out.println(worker.getName() + "等待" + administrator.getName() + "打开仓库门");
                try {
                    administrator.start();
                    administrator.join();//当前线程开始等待administrator结束
                } catch (InterruptedException e) {
                }
                System.out.println(worker.getName() + "启动车辆装载货物完毕");
            } else if (Thread.currentThread() == administrator) {
                System.out.println(administrator.getName() + "开始打开仓库的门，请稍等.");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {}
                    System.out.println(administrator.getName() + "打开了仓库门");
                }
            }
        }